#!/user.bin/env bash

master_ip=`head -1 /tmp/hosts |awk '{print $1}'`

ssh $master_ip 'kubectl get nodes|grep -q `hostname`|grep "Ready"'

if [ $? -eq 0 ];then
    exit 0
fi

CERT_KEY=`ssh $master_ip "kubeadm init phase upload-certs --upload-certs|tail -1"`

join_str=`ssh $master_ip kubeadm token create --print-join-command`

$( echo $join_str " --certificate-key $CERT_KEY --v=5")